package com.bb.blog.biz.manage.controller;

import com.bb.blog.biz.manage.constant.ManageValidGroup;
import com.bb.blog.biz.manage.model.SysMenu;
import com.bb.blog.biz.manage.service.SysMenuService;
import com.bb.blog.web.component.ResponseUtil;
import com.bb.blog.web.model.CommonResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/menu")
public class MenuController {
    private final SysMenuService sysMenuService;

    @GetMapping("/list")
    public CommonResponse<Object> menuList(
            @RequestParam(required = false) Integer userId,
            @RequestParam(required = false) String systemId,
            @RequestParam(required = false) List<Byte > status){

        List<SysMenu> sysMenus = sysMenuService.menuList(systemId, userId, status);
        return ResponseUtil.success(sysMenus);
    }
    @PostMapping
    public CommonResponse<Object> addMenu(@Validated(ManageValidGroup.MenuAdd.class) @RequestBody SysMenu  addMenu){
        sysMenuService.addMenu(addMenu);
        return ResponseUtil.success("操作成功");
    }
    @PutMapping
    public CommonResponse<Object> edit(@Validated(ManageValidGroup.MenuEdit.class) @RequestBody SysMenu editMenu){
        sysMenuService.editMenu(editMenu);
        return ResponseUtil.success("操作成功");
    }
    @DeleteMapping
    public CommonResponse<Object> del(Integer id){
        sysMenuService.delMenu(id);
        return ResponseUtil.success("操作成功");
    }
}
